package cn.seaboot.admin.api.service;

import cn.seaboot.admin.api.bean.ApiMapping;
import cn.seaboot.admin.api.dao.ApiMappingDao;
import cn.seaboot.commons.core.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Service
 * 系统地址信息 [t_api_mapping]
 *
 * @author Mr.css on 2018-6-20
 */
@Service
public class ApiMappingService {
    private Logger logger = LoggerFactory.getLogger(ApiMappingService.class);

    @Resource
    private ApiMappingDao apiMappingDao;

    /**
     * 增
     *
     * @param pojo pojo
     * @return affected rows
     */
    public int insert(ApiMapping pojo) {
        return apiMappingDao.insert(pojo);
    }

    /**
     * 增
     *
     * @param list pojo
     * @return affected rows
     */
    public void insertBatch(List<ApiMapping> list) {
        for (ApiMapping pojo : list) {
            apiMappingDao.insert(pojo);
        }
    }

    /**
     * 删
     *
     * @param id id
     * @return affected rows
     */
    public int deleteById(String id) {
        return apiMappingDao.deleteById(id);
    }

    /**
     * 删
     *
     * @param projectId 工程ID
     * @return affected rows
     */
    public int deleteByProjectId(String projectId) {
        return apiMappingDao.deleteByProjectId(projectId);
    }

    /**
     * 改
     *
     * @param pojo pojo
     * @return affected rows
     */
    public int updateById(ApiMapping pojo) {
        return apiMappingDao.updateSampleById(pojo);
    }

    /**
     * 查
     *
     * @param id id
     * @return pojo
     */
    public ApiMapping queryById(String id) {
        return apiMappingDao.selectById(id);
    }

    /**
     * 查
     *
     * @param url           url
     * @param requestMethod requestMethod
     * @return pojo
     */
    public ApiMapping queryByUrl(String url, String requestMethod) {
        return apiMappingDao.selectByUrl(url, requestMethod);
    }

    /**
     * 查列表
     *
     * @param projectId 工程ID
     * @return list
     */
    public List<ApiMapping> queryByProjectId(String projectId) {
        Map<String, Object> params = MapUtils.newMap("projectId", projectId);
        return apiMappingDao.selectList(params);
    }

    /**
     * 查列表
     *
     * @param params 参数
     * @return list
     */
    public List<ApiMapping> queryList(Map<String, Object> params) {
        return apiMappingDao.selectList(params);
    }
}
